#! /usr/bin/env python
# -*- coding: utf-8 -*-

# *************************************************************
#  Copyright (c) Huoty - All rights reserved
#
#      Author: Huoty <sudohuoty@gmail.com>
#  CreateTime: 2017-02-10 10:45:06
# *************************************************************

"""tornado RequestHandler 获取客户端请求参数的几个方法的比较

get_argument
get_arguments
get_query_argument
get_query_arguments
get_body_argument
get_body_arguments
"""

from __future__ import print_function

import tornado.ioloop
import tornado.web
from tornado.log import app_log as log

import tornado.options
tornado.options.parse_command_line()


class MainHandler(tornado.web.RequestHandler):

    def prepare(self):
        log.info(self.get_argument("test"))
        log.info(self.get_arguments("test"))
        log.info(self.get_query_argument("test"))
        log.info(self.get_query_arguments("test"))
        log.info(self.get_body_argument("test"))
        log.info(self.get_body_arguments("test"))

    def get(self):
        self.write("ok")

    def post(self):
        self.write("ok")

# Script starts from here

if __name__ == "__main__":
    application = tornado.web.Application([
        (r"/", MainHandler),
    ], debug=True)
    application.listen(12901)
    tornado.ioloop.IOLoop.current().start()
